<?php
function arr_diff($a1,$a2){
    foreach($a1 as $k=>$v){
        if (!isset($a2[$k])) { return false;}
        
        if (is_array($v)) {
            if (is_array($a2[$k])) {
                if (!arr_diff($v, $a2[$k])) {
                    return false;
                }
            } else {
                return false;
            }
        } elseif ($v != $a2[$k]) {
            echo "$v != ". $a2[$k]."\n";
            return false;
        }
    }
    foreach ($a2 as $k=>$v) {
        if (!isset($a1[$k])) { return false;}
        
        if (is_array($v)) {
            if (is_array($a1[$k])) {
                if (!arr_diff($v, $a1[$k])) {
                    return false;
                }
            } else {
                return false;
            }
        } elseif ($v != $a1[$k]) {
            echo "$v != ". $a1[$k]."\n";
            return false;
        } else {
        }
    }
    return true;
}
/*
if (arr_diff(array(
        'test' => 1,
        'test2' => array(1,2,3),
        'test3' => array(1,2,'ab' => 'blah'),
        'test4' => array(1,2,'ab' => 'blah', array(1,3)),
    ), array(
        'test' => 1,
        'test2' => array(1,2,3),
        'test3' => array(1,2,'ab' => 'blah'),
        'test4' => array(1,2,'ab' => 'blah', array(1,3)),
    ))) {
    echo 'passed';
} else {
    echo 'failed';
}
exit;
*/
require('../wordpress-reports/lib.googleanalytics.php');
$ga = new tantan_GoogleAnalytics();
$passed = true;
if (!arr_diff($c = $ga->_parseCSV(file_get_contents('data.csv')), $x = $ga->_parseXML(file_get_contents('data.xml')))) {
    echo "FAILED data.csv and data.xml<br>";
    echo "\n\nCSV:\n";
    print_r($c);
    echo "\n\nXML:\n";
    print_r($x);
    $passed = false;
}elseif (!arr_diff($c = $ga->_parseCSV(file_get_contents('data2.csv')), $x = $ga->_parseXML(file_get_contents('data2.xml')))) {
    echo "FAILED data2.csv and data2.xml<br>";
    echo "\n\nCSV:\n";
    print_r($c);
    echo "\n\nXML:\n";
    print_r($x);
    echo $passed = false;
}


if ($passed) {
    echo "PASSED ALL TESTS<br><br><br>\n\n\n\n";
} else {
    echo "FAILED";
}
    echo "\n\nCSV:\n";
    print_r($c);
    echo "\n\nXML:\n";
    print_r($x);
?>